<template>
    <div class="content">
        <el-row :gutter="20">
            <el-col :span="12">
                <el-button type="primary" :icon="CirclePlus" >添加</el-button>
            </el-col>
            <el-col :span="12" class="text-right">
                <el-input v-model="form.search" style="width: 240px" placeholder="请输入关键词" />
                <el-button type="primary" class="ml10" :icon="Search" @click="onSearch">搜索</el-button>
                <el-button type="primary" class="ml10" :icon="RefreshRight" @click="onSearch('Refresh')" />
            </el-col>
        </el-row>
        
        <el-table class="mt20" :data="tableData" border v-loading="form.loading" style="width: 100%;font-size: 16px;" @cell-dblclick="onCellDb">
            <el-table-column type="index" :index="indexMethod" label="序号" width="60" />
            <el-table-column prop="title" label="批次" show-overflow-tooltip />
            <el-table-column prop="start_date" label="发票张数" width="110"/>
            <el-table-column prop="end_date" label="发票类型" width="110" />
            <el-table-column prop="start_date" label="发票号" width="110"/>
            <el-table-column prop="end_date" label="开票日期" width="110" />
            <el-table-column prop="start_date" label="开票项目" width="110"/>
            <el-table-column prop="end_date" label="开票金额" width="110" />
            <el-table-column prop="start_date" label="到账资金" width="110"/>
            <el-table-column prop="end_date" label="备注" width="110" />
            <el-table-column fixed="right" label="操作" width="150">
                <template #default="scope">
                    <el-link link type="primary" @click="onEdit(scope.row.id)" >编辑</el-link>
                    <el-popconfirm title="确定要删除么?" @confirm="onDelete(scope.row.id)">
                        <template #reference>
                            <el-link link type="danger" >删除</el-link>
                        </template>
                    </el-popconfirm>
                </template>
            </el-table-column>
        </el-table>
        <div class="mt20">
            <el-pagination v-model:current-page="form.current" v-model:page-size="form.limit" :page-sizes="[10, 20, 30, 40, 50, 100]" layout="total, sizes, prev, pager, next, jumper" :total="form.total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
        </div>
    </div>

</template>

<script lang="ts" setup>
import { ref,onMounted } from 'vue'
import router from '../../../router';
import { CirclePlus, RefreshRight, Search } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'
// import http from '../../../util/request';
const indexMethod = (index: number) => {
  return index+= 1
}
const form = ref<any>({search:'',page:0,current:0,total:10,limit:20,loading:false,parentBorder:false})
interface Project {
    id: number
    batch: string
    invoice_sum: number
    invoice_type: string
    invoice_number: string
    invoice_date: string
    project_id: string
    invoice_price: string
    received_price: string
    received_date: string
    remark: string
}
const tableData = ref<Project[]>([])

const onGetData = () => {
    console.log('请求')
    form.value.page = 0;
    // form.value.loading = true
    // http.post('/project',form.value).then((response:any)=>{
    //     form.value.loading = false
    //     tableData.value = response.data.data
    //     form.value.total = response.data.total
    // })
}

const onSearch = (type = '') => {
    if(type == 'Refresh'){
        form.value.search = ''
        onGetData()
        return
    }
    if(!form.value.search){
        ElMessage.error('请输入搜索内容')
    }
    form.value.page = 1
    onGetData()
}


const onCellDb = (data: Project) => {
    console.log(data)
}

const onEdit = (data: number) => {
    router.push({ name: 'projectEdit',params: { id: data }})
}

const onDelete = (id: number) => {
    ElMessage.success(id+'删除操作');
    // http.delete('/project/'+id).then((response:any)=>{
    //     if(response.data.code != 200){
    //         ElMessage.error(response.data.msg);return;
    //     }
    //     ElMessage.success(response.data.msg);
    //     onGetData();
    // })
}
const handleSizeChange = (val: number) => {
    form.value.limit = val
    onGetData()
}
const handleCurrentChange = (val: number) => {
    form.value.page = val
    onGetData()
}
onMounted(()=>{
    onGetData()
})

</script>

<style scoped>

</style>